package com.fau.om.util;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @desc 发送Http请求工具类
 * @author liy
 * @datetime 2014年10月24日,下午10:46:33
 */
@Component
public class HttpRequestUtil {
	
	private static final Logger log = Logger.getLogger(HttpRequestUtil.class);
	
	@Value("${server.local.name}")
	private String urlPath;
	
	/**
	 * @desc 订单审核不通过提醒
	 * @param content 提醒内容
	 * @param eid 企业id
	 * @param operatorId 提醒人id
	 * @author kangyj
	 * @datetime 2015年1月15日,上午11:19:08
	 */
	@Async
	public void allocateRemind(String content, String eid, String operatorId) {
		
		StringBuilder get_url = new StringBuilder(urlPath);
		get_url.append("/sd/AllocateServlet");
		get_url.append("?operatorId=").append(operatorId);
		get_url.append("&eid=").append(eid);
		
		try {
			get_url.append("&content=").append(content);
			URL getUrl= new URL(get_url.toString());
			
			HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection();
			connection.setConnectTimeout(5000);  
			connection.setReadTimeout(5000);
			connection.connect();
			connection.getInputStream();
			connection.disconnect();
		} catch (IOException e) {
			log.error(e.getMessage());
		}
	}
	
	public String getUrlPath() {
		return urlPath;
	}

	public void setUrlPath(String urlPath) {
		this.urlPath = urlPath;
	}
	
}